package com.lipaluma.field.validator.impl.date;

import java.lang.reflect.Field;

import com.lipaluma.annotations.validations.ValidateDate;
import com.lipaluma.context.Context;
import com.lipaluma.field.validator.impl.generic.AbstractUniqueValidator;

/**
 * Check that the field value must be unique
 * 
 * To initialize : 
 * <ul>
 * 	<li>
 * 	<u><b>By annotations :</b></u> There are 2 ways to initialize the unique validator by annotations.<br>
 * 	<ul>
 *  <li>Use {@link ValidateDate} and put the <code>unique</code> attribute at true.<br/></li>
 *  <li>Just add the {@link Unique} annotation.<br/></li>
 *  </ul>
 * 	</li>
 * 	<li>
 * 	<u><b>By Xml :</b></u>
 * <ul>
 * <li>
 * To add the unique validation, see the example below : <br/>
 * <code>
 * &lt;ToMap field="..." <b>unqiue="true"</b>/><br/>
 * </code>
 * </li>
 * </ul>
 * @author msoares
 *
 */
public class DateUniqueValidator extends AbstractUniqueValidator {
	
	@Override
	public boolean init(Context context, Field field) {
		ValidateDate annotation = field.getAnnotation(ValidateDate.class);
		return annotation != null && annotation.unique();
	}
}
